#include "systemcontrol.h"
#include <QSettings>
#include "mytcpserver.h"
#include <QDebug>
#define CONFIGFILENAME "config.ini"
#define DEFGROUP  "set"
#define SERVERLISTENPORT "listen_port"

SystemControl::SystemControl(QObject *parent) : QObject(parent)
  ,server(new MyTcpServer)
{

}

void SystemControl::initSystem()
{
    qDebug()<< "system_init";
}

void SystemControl::startSystem()
{
  int port = getServerListenPort();
  bool ok = server->listen(QHostAddress::Any,port);
  qDebug() << "system start:listen" << port << " " << (ok? "ok" : "error");
}

int SystemControl::getServerListenPort()
{
QSettings set(CONFIGFILENAME,QSettings::IniFormat);
set.beginGroup(DEFGROUP);
if(!set.allKeys().contains(SERVERLISTENPORT))
    set.setValue(SERVERLISTENPORT,10086);
int port = set.value(SERVERLISTENPORT).toInt();
set.endGroup();
return port;
}
